package edu.luc.cs.backend;
/**
 * Person Class
 * Represents a person, contains Name, Date of Birth,
 * Sex, and Eye Color
 * 
 * Equality is defined by the equality of all attributes
 * @author Christopher Bun
 *
 */


public class Person {
	//Internal Representation
	private PersonName name;
	private Date dob;
	private char sex;
	private String eyeColor;
	
	/**
	 * Constructor
	 * @param familyName Person's family name or last name
	 * @param givenName Person's given name or first and/or middle name
	 * @param yyyy Year the person was born
	 * @param mm Month the person was born
	 * @param dd Day of the month the person was born
	 * @param sex Gender of the person (e.g. male, m, Female)
	 * @param eyeColor Color of the person's eyes (e.g. Brown, blue)
	 */
	public Person(String familyName, String givenName, int yyyy, int mm,
									 int dd, String sex, String eyeColor) {
		setName(familyName, givenName);
		setDob(yyyy, mm, dd);
		setSex(sex);
		setEyeColor(eyeColor);
	}

	//--------------ACCESSOR FUNCTIONS------------------------//
	
	public void setName(String familyName, String givenName) {
		this.name = new PersonName(familyName, givenName);
	}
	
	public PersonName getName() {
		return name;
	}
	
	public void setDob(int yyyy, int mm, int dd) {
		dob = new Date(yyyy, mm, dd);
	}
	
	public Date getDob() {
		return dob;
	}
	
	//Case-insensitive truncation of the sex parameter to 1 char
	public void setSex(String sex) {
		this.sex = sex.toLowerCase().charAt(0);
	}
	
	public char getSex() {
		return sex;
	}
	
	//Case-insensitive truncation of the eyeColor parameter to 3 char
	public void setEyeColor(String eyeColor) {
		this.eyeColor = eyeColor.toLowerCase().substring(0, 3);
	}
	
	public String getEyeColor() {
		return eyeColor;
	}
	
	//-------------Comparison Method-------------------//
	public boolean equals(Person p) {
		return this.name.equals(p.name) 		&&
			   this.dob.equals(p.dob)   		&&
			   this.eyeColor.equals(p.eyeColor) &&
			   this.sex == p.sex;
	}
	
	//-------------External Representation---------------//
	public String toString() {
		return "Name: " 	 + name.toString() + 
			 "\nDOB:  " 	 + dob.toString()  +
			 "\nSex:  " 	 + sex             +
			 "\nEye Color: " + eyeColor;
	}
}
